﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace ADO_Task_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = GetConnectionString();
            string queryString = "SELECT Sno,Sname From dbo.Student;";
            using (SqlConnection connection = new SqlConnection(connectionString)) 
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandText = queryString;
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Console.WriteLine("\t{0}\t{1}", reader[0], reader[1]);
                    }
                    Console.ReadKey();
                    reader.Close();
                }
                catch (Exception ex)
                {

                    Console.WriteLine(ex.Message);
                }
            }
        }

        private static string GetConnectionString()
        {
            return "Data source = (local);Initial Catalog = Northwid;" + "IntegratedSecurity=SSPI";
        }
    }
}
